
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        12/25/2008
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteProductCommentDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;
using System.Data;

namespace MCWEBSITE.DAL
{
    public class websiteProductCommentDAL
    {
        #region  Properties

        public static string FIELD_COMMENTID = "CommentID";
        public static string FIELD_PRODUCTID = "ProductID";
        public static string FIELD_LANGUAGECODE = "LanguageCode";
        public static string FIELD_CONTENT = "Content";
        public static string FIELD_CREATER = "Creater";
        public static string FIELD_CREATEDATE = "CreateDate";
        public static string FIELD_ISACTIVE = "IsActive";
        public static string FIELD_ATRIBUTE1 = "Atribute1";
        public static string FIELD_ATRIBUTE2 = "Atribute2";
        public static string FIELD_ATRIBUTE3 = "Atribute3";
        public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteProductComment
        /// </summary>
        /// <param name="CommentID">Primary Keys</param>
        /// <returns>Collection of websiteProductCommentInfo</returns>
        public static websiteProductCommentInfo SelectOne(int CommentID)
        {
            websiteProductCommentInfo _websiteProductCommentInfo = new websiteProductCommentInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductCommentSelectOne", CommentID);
                if (dr.Read())
                    setwebsiteProductCommentInfo(dr, ref _websiteProductCommentInfo);
                return _websiteProductCommentInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteProductComment
        /// </summary>
        /// <returns>Collection of websiteProductCommentInfo</returns>
        public static List<websiteProductCommentInfo> SelectAll()
        {
            List<websiteProductCommentInfo> lstwebsiteProductComment = new List<websiteProductCommentInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductCommentSelectAll");
                setListwebsiteProductCommentInfo(ref dr, ref lstwebsiteProductComment);
                return lstwebsiteProductComment;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteProductCommentnfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteProductCommentInfo</returns>
        public static List<websiteProductCommentInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteProductCommentInfo> lstwebsiteProductComment = new List<websiteProductCommentInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductCommentSelectByFilters");
                setListwebsiteProductCommentInfo(ref dr, ref lstwebsiteProductComment);
                return lstwebsiteProductComment;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteProductComment
        /// </summary>
        /// <param name="websiteProductCommentInfo">Entity of websiteProductComment</param>
        /// <returns>error code</returns>
        public static int Insert(websiteProductCommentInfo _websiteProductCommentInfo)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteProductCommentInsert"
                                            , _websiteProductCommentInfo.ProductID
                                            , _websiteProductCommentInfo.LanguageCode
                                            , _websiteProductCommentInfo.Content
                                            , _websiteProductCommentInfo.Creater                                            
                                            , _websiteProductCommentInfo.Atribute1                                            
                                            );
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Update websiteProductComment
        /// </summary>
        /// <param name="websiteProductCommentInfo">Entity of websiteProductComment</param>
        /// <returns>error code</returns>
        public static int Update(websiteProductCommentInfo _websiteProductCommentInfo)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteProductCommentUpdate"
                                            , _websiteProductCommentInfo.CommentID
                                            , _websiteProductCommentInfo.ProductID
                                            , _websiteProductCommentInfo.LanguageCode
                                            , _websiteProductCommentInfo.Content
                                            , _websiteProductCommentInfo.Creater
                                            , _websiteProductCommentInfo.CreateDate
                                            , _websiteProductCommentInfo.IsActive
                                            , _websiteProductCommentInfo.Atribute1
                                            , _websiteProductCommentInfo.Atribute2
                                            , _websiteProductCommentInfo.Atribute3
                                            );
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="CommentID">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int CommentID)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteProductCommentDelete", CommentID);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        public static DataSet SelectByProduct(int ItemId)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_mc_websiteProductCommentGetByProduct", ItemId);
                return ds;
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        public static int GetCountComment(int ItemID)
        {
            try
            {
                return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_mc_websiteProductCommentGetCount", ItemID));
            }
            catch (Exception ex)
            {
                return -1;
            }
        }


        #endregion

        #region "Utilities method"

        private static void setListwebsiteProductCommentInfo(ref SqlDataReader dr, ref List<websiteProductCommentInfo> lstwebsiteProductComment)
        {
            websiteProductCommentInfo _websiteProductCommentInfo = null;
            while (dr.Read())
            {
                _websiteProductCommentInfo = new websiteProductCommentInfo();
                setwebsiteProductCommentInfo(dr, ref _websiteProductCommentInfo);
                lstwebsiteProductComment.Add(_websiteProductCommentInfo);
            }
        }

        private static void setwebsiteProductCommentInfo(SqlDataReader dr, ref websiteProductCommentInfo _websiteProductCommentInfo)
        {
            _websiteProductCommentInfo.CommentID = dr[websiteProductCommentDAL.FIELD_COMMENTID] != DBNull.Value ? Convert.ToInt32(dr[websiteProductCommentDAL.FIELD_COMMENTID]) : 0;
            _websiteProductCommentInfo.ProductID = dr[websiteProductCommentDAL.FIELD_PRODUCTID] != DBNull.Value ? Convert.ToInt32(dr[websiteProductCommentDAL.FIELD_PRODUCTID]) : 0;
            _websiteProductCommentInfo.LanguageCode = dr[websiteProductCommentDAL.FIELD_LANGUAGECODE] != DBNull.Value ? Convert.ToString(dr[websiteProductCommentDAL.FIELD_LANGUAGECODE]) : string.Empty;
            _websiteProductCommentInfo.Content = dr[websiteProductCommentDAL.FIELD_CONTENT] != DBNull.Value ? Convert.ToString(dr[websiteProductCommentDAL.FIELD_CONTENT]) : string.Empty;
            _websiteProductCommentInfo.Creater = dr[websiteProductCommentDAL.FIELD_CREATER] != DBNull.Value ? Convert.ToString(dr[websiteProductCommentDAL.FIELD_CREATER]) : string.Empty;
            _websiteProductCommentInfo.CreateDate = dr[websiteProductCommentDAL.FIELD_CREATEDATE] != DBNull.Value ? Convert.ToDateTime(dr[websiteProductCommentDAL.FIELD_CREATEDATE]) : DateTime.Now;
            _websiteProductCommentInfo.IsActive = dr[websiteProductCommentDAL.FIELD_ISACTIVE] != DBNull.Value ? Convert.ToBoolean(dr[websiteProductCommentDAL.FIELD_ISACTIVE]) : false;
            _websiteProductCommentInfo.Atribute1 = dr[websiteProductCommentDAL.FIELD_ATRIBUTE1] != DBNull.Value ? Convert.ToString(dr[websiteProductCommentDAL.FIELD_ATRIBUTE1]) : string.Empty;
            _websiteProductCommentInfo.Atribute2 = dr[websiteProductCommentDAL.FIELD_ATRIBUTE2] != DBNull.Value ? Convert.ToString(dr[websiteProductCommentDAL.FIELD_ATRIBUTE2]) : string.Empty;
            _websiteProductCommentInfo.Atribute3 = dr[websiteProductCommentDAL.FIELD_ATRIBUTE3] != DBNull.Value ? Convert.ToString(dr[websiteProductCommentDAL.FIELD_ATRIBUTE3]) : string.Empty;

        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteProductComment]";

        #endregion
    }
}

